﻿using System.IO;
using GameFramework.Extensions;
using GameFramework.GameObjects;
using GameFramework.VisualTests.Content;
using Microsoft.Xna.Framework;

namespace GameFramework.VisualTests.Screens
{
    public class TextTest : Screen
    {
        private Label text1;
        private Label text2;
        private Label text3;
        private Label text4;
        private Label text5;
        private Label text6;
        private Label text7;
        private Label text8;
        private Label text9;

        public TextTest()
        {
            text1 = new Label
                    {
                        FontName = Fonts.Text,
                        Text = "(L, T)",
                        Color = Color.White,
                        Angle = 0,
                        HorizontalTextAlignment = HorizontalTextAlignment.Left,
                        VerticalTextAlignment = VerticalTextAlignment.Top,
                        Position = new Vector2(0, 0),
                        LayerDepth = 0,
                        Scale = new Vector2(1)
                    };

            text2 = new Label
                    {
                        FontName = Fonts.Text,
                        Text = "(C, T)",
                        Color = Color.Yellow,
                        Angle = 0,
                        HorizontalTextAlignment = HorizontalTextAlignment.Center,
                        VerticalTextAlignment = VerticalTextAlignment.Top,
                        Position = new Vector2(ScreenWidth / 2, 0),
                        LayerDepth = 0,
                        Scale = new Vector2(1f)
                    };

            text3 = new Label
                    {
                        FontName = Fonts.Text,
                        Text = "(R, T)",
                        Color = Color.Green,
                        Angle = 0,
                        HorizontalTextAlignment = HorizontalTextAlignment.Right,
                        VerticalTextAlignment = VerticalTextAlignment.Top,
                        Position = new Vector2(ScreenWidth, 0),
                        LayerDepth = 0,
                        Scale = new Vector2(1f)
                    };

            text4 = new Label
                    {
                        FontName = Fonts.Text,                        
                        Text = "(L, C)",
                        Color = Color.White,
                        Angle = 0,
                        HorizontalTextAlignment = HorizontalTextAlignment.Left,
                        VerticalTextAlignment = VerticalTextAlignment.Center,
                        Position = new Vector2(0, ScreenHeight / 2),
                        LayerDepth = 0,
                        Scale = new Vector2(1),
                    };

            text5 = new Label
                    {
                        FontName = Fonts.Text,
                        Text = "(C, C)",
                        Color = Color.Yellow,
                        Angle = 0,
                        HorizontalTextAlignment = HorizontalTextAlignment.Center,
                        VerticalTextAlignment = VerticalTextAlignment.Center,
                        Position = new Vector2(ScreenWidth / 2, ScreenHeight / 2),
                        LayerDepth = 0,
                        Scale = new Vector2(2)
                    };

            text6 = new Label
                    {
                        FontName = Fonts.Text,
                        Text = "(R, C)",
                        Color = Color.Green,
                        Angle = 0,
                        HorizontalTextAlignment = HorizontalTextAlignment.Right,
                        VerticalTextAlignment = VerticalTextAlignment.Center,
                        Position = new Vector2(ScreenWidth, ScreenHeight / 2),
                        LayerDepth = 0,
                        Scale = new Vector2(1)
                    };

            text7 = new Label
                    {
                        FontName = Fonts.Text,
                        Text = "(L, B)",
                        Color = Color.White,
                        Angle = 0,
                        HorizontalTextAlignment = HorizontalTextAlignment.Left,
                        VerticalTextAlignment = VerticalTextAlignment.Bottom,
                        Position = new Vector2(0, ScreenHeight),
                        LayerDepth = 0,
                        Scale = new Vector2(1)
                    };

            text8 = new Label
                    {
                        FontName = Fonts.Text,
                        Text = "(C, B)",
                        Color = Color.Yellow,
                        Angle = 0,
                        HorizontalTextAlignment = HorizontalTextAlignment.Center,
                        VerticalTextAlignment = VerticalTextAlignment.Bottom,
                        Position = new Vector2(ScreenWidth / 2, ScreenHeight),
                        LayerDepth = 0,
                        Scale = new Vector2(1)
                    };

            text9 = new Label
                    {
                        FontName = Fonts.Text,
                        Text = "(R, B)",
                        Color = Color.Green,
                        Angle = 0,
                        HorizontalTextAlignment = HorizontalTextAlignment.Right,
                        VerticalTextAlignment = VerticalTextAlignment.Bottom,
                        Position = new Vector2(ScreenWidth, ScreenHeight),
                        LayerDepth = 0,
                        Scale = new Vector2(1)
                    };

            Children.Add(text1);
            Children.Add(text2);
            Children.Add(text3);
            Children.Add(text4);
            Children.Add(text5);
            Children.Add(text6);
            Children.Add(text7);
            Children.Add(text8);
            Children.Add(text9);
        }

        public override void Update()
        {
            base.Update();

            if (IsBackButtonPressed)
            {
                Game.Exit();
            }
        }

        public override void Read(BinaryReader reader)
        {
            base.Read(reader);

            text1 = reader.ReadObject<Label>();
            text2 = reader.ReadObject<Label>();
            text3 = reader.ReadObject<Label>();
            text4 = reader.ReadObject<Label>();
            text5 = reader.ReadObject<Label>();
            text6 = reader.ReadObject<Label>();
            text7 = reader.ReadObject<Label>();
            text8 = reader.ReadObject<Label>();
            text9 = reader.ReadObject<Label>();
        }

        public override void Write(BinaryWriter writer)
        {
            base.Write(writer);

            writer.WriteObject(text1);
            writer.WriteObject(text2);
            writer.WriteObject(text3);
            writer.WriteObject(text4);
            writer.WriteObject(text5);
            writer.WriteObject(text6);
            writer.WriteObject(text7);
            writer.WriteObject(text8);
            writer.WriteObject(text9);
        }
    }
}